﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 

namespace PresentationLayer.Presenters
{
    using WinFormsMvp;
    using PresentationLayer.Views.ViewContracts;
    using EngineLayer;
    using System.Data;
    using System.Windows.Forms;
    using PresentationLayer.Properties;
    using EngineLayer.Model;

    public class CashierPresenter : Presenter<ICashierView>
    {
        public CashierPresenter(ICashierView view)
            : base(view)
        {
            View.CloseFormClicked += View_CloseFormClicked;
            View.TextBoxFindChanged += View_TextBoxFindChanged;
            View.Load += View_Load;
        }

        void View_CloseFormClicked(object sender, EventArgs e)
        {
            View.CloseForm();
        }

        void View_Load(object sender, EventArgs e)
        {
             View.Model = new CashierModel();
        }
        private void View_TextBoxFindChanged(object sender, EventArgs e)
        {
           // View.Binding(View.Model.ProductService().FilterByProductNameOrID(((TextBox)sender).Text).AsEnumerable());
            //Product test = View.Model.product();
            //test.Id = 1;
            //test.Name = "Rob";

            //var TESTING = View.Model.ProductService().GetAllProductsShort();

            MyApplication application;

            Logon logon = new Logon();
            User user = new User();
            user.UserName = "sysadmin";
            user.PassWord = "sysadmin";
            logon.user = user;

            application = logon.OpenApplication(logon);

            application.Libraries.Products.BeginEdit();

            //foreach (var t in application.Libraries.Products)
            //{
            //    string test = t.Name.Value;
            //    t.Delete();
            //    try
            //    {
            //        t.BeginEdit();
            //        t.Name.Value = "Teriyaki de polloRRR".ToUpper();
            //       // t.Id.Value = 1111;
            //        t.EndEdit();
            //    }
            //    catch(Exception ex)
            //    {
            //        System.Windows.Forms.MessageBox.Show(ex.Message);
            //    }
                
            //}

            Product p = application.Libraries.Products.Find(32);
            p.Delete();
            application.Libraries.Products.EndEdit();
            
        }
    }
}
